package com.example.dormitory.service;


import com.example.dormitory.entity.*;
import com.example.dormitory.mapper.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


@Service
public class StayRecordService {

    @Autowired
    private StayRecordMapper stayRecordMapper;

    public int create(StayRecord stayRecord) {
        return stayRecordMapper.create(stayRecord);
    }

    public int delete(String ids) {
        String[] arr = ids.split(",");
        int row = 0;
        for (String s : arr) {
            if(!StringUtils.isEmpty(s)){
                stayRecordMapper.delete(Integer.parseInt(s));
            row++;
            }
        }
        return row;
    }

    public int delete(Integer id) {
        return stayRecordMapper.delete(id);
    }

    public int update(StayRecord stayRecord) {
        return stayRecordMapper.update(stayRecord);
    }

    public int updateSelective(StayRecord stayRecord) {
        return stayRecordMapper.updateSelective(stayRecord);
    }

    public PageInfo<StayRecord> query(StayRecord stayRecord) {
        if(stayRecord != null && stayRecord.getPage() != null){
            PageHelper.startPage(stayRecord.getPage(),stayRecord.getLimit());
        }
        return new PageInfo<StayRecord>(stayRecordMapper.query(stayRecord));
    }

    public StayRecord detail(Integer id) {
        return stayRecordMapper.detail(id);
    }

    public int count(StayRecord stayRecord) {
        return stayRecordMapper.count(stayRecord);
    }
}
